package org.display.util
{
	import flash.filesystem.*;
	
	import mx.controls.Alert;
	import mx.managers.PopUpManager;
	
	import org.abcFrame.core.*;
	import org.data.*;
	import org.events.*;
	import org.net.*;
	import org.utils.*;
	
	public class Login
	{
		public function Login(label:String,addFolderPannel:ETitlePannel,app:*)
		{
			var res:AbcResponder=new AbcResponder()
			res.onResult=function(e,path){
				
				var lock:Boolean=false
				
				var arr:Array=e.split(",")
					
				for(var i=0;i<arr.length;i++){
					
					if(arr[i]==label){

						lock=true
						
					}
				}
				
				//不用用户名登陆或是有效登录用户名
				if(lock||label==""){
					
					Global.username=label
					
					//保存当前用户名
					var xmlpath:String=String(File.applicationDirectory.nativePath+"/config.xml").replace(new RegExp("\/","gis"),"\\")
					Global.configData.user=label
					FileControl.saveFile(xmlpath,Global.configData.toXMLString())
					
					//新建文件夹
					var path:String=Global.workspace.replace(/\\/gis,"/")+"/org/display/"+Global.username
					var source:File = File.desktopDirectory.resolvePath(path);
					source.createDirectory();
					
					//获取CommandControl.as文件对象
					path=Global.workspace.replace(/\\/gis,"/")+"/org/control/"+Global.username+"/CommandControl.as"
					source = File.desktopDirectory.resolvePath(path);
					
					//如果commandControl.as已经存在，则重新加载，如果没有则生成
					if(source.exists==false){
						
						if(label!=""){
						   Global.commandControlSource=Global.commandControlSource.replace("<username>",label)
						}else{
						   Global.commandControlSource=Global.commandControlSource.replace(".<username>",label)
						}
							
						FileControl.saveFile(path,Global.commandControlSource)	
						
					}else{
						
						var res:AbcResponder=new AbcResponder()
						res.onResult=function(e,path){
							
							Global.commandControlSource=e
							
						}
						new AbcHTTPServices(path,res)
						
					}
					
					PopUpManager.removePopUp(addFolderPannel);
					
					//自动锁定发布文件夹
					if(Global.username!=""){
						Global.lockPath="\\org\\display"+Global.username
					}else{
						Global.lockPath="\\org\\display\\main"
					}
					
					app.title="AcbFrame—"+"锁定发布文件夹"+Global.lockPath+"—"+Global.workspace
					
					Alert.show("自动锁定发布文件"+Global.lockPath)
				
				}else{
					Alert.show("查无此人！")
				}
				
				Global.openDefault()
				
			}
				
			res.onFault=function(){
			
			
				Global.username=label
				
				//保存当前用户名
				var xmlpath:String=String(File.applicationDirectory.nativePath+"/config.xml").replace(new RegExp("\/","gis"),"\\")
				Global.configData.user=label
				FileControl.saveFile(xmlpath,Global.configData.toXMLString())
				
				//新建文件夹
				var path:String=Global.workspace.replace(/\\/gis,"/")+"/org/display/"+Global.username
				var source:File = File.desktopDirectory.resolvePath(path);
				source.createDirectory();
				
				//获取CommandControl.as文件对象
				path=Global.workspace.replace(/\\/gis,"/")+"/org/control/"+Global.username+"/CommandControl.as"
				source = File.desktopDirectory.resolvePath(path);
				
				//如果commandControl.as已经存在，则重新加载，如果没有则生成
				if(source.exists==false){
					
					if(label!=""){
						Global.commandControlSource=Global.commandControlSource.replace("<username>",label)
					}else{
						Global.commandControlSource=Global.commandControlSource.replace(".<username>",label)
					}
					
					FileControl.saveFile(path,Global.commandControlSource)	
					
				}else{
					
					var res:AbcResponder=new AbcResponder()
					res.onResult=function(e,path){
						
						Global.commandControlSource=e
						
					}
					new AbcHTTPServices(path,res)
					
				}
				
				PopUpManager.removePopUp(addFolderPannel);
				
				//自动锁定发布文件夹
				if(Global.username!=""){
					Global.lockPath="\\org\\display\\"+Global.username
				}else{
					Global.lockPath="\\org\\display\\main"
				}
				
				app.title="AcbFrame—"+"锁定发布文件夹"+Global.lockPath+"—"+Global.workspace
					
				
				
				Alert.show("自动锁定发布文件"+Global.lockPath)
			
				Global.openDefault()
			
			}
				
			res.onFault()
				
			//new AbcHTTPServices("http://www.wakao123.com/user.txt",res)
			
		}
		
		
	}
}